package com.kksoft.readcm.objects;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Filter;
import android.widget.Filterable;

import com.kksoft.readcm.activity.App;
import com.kksoft.readcm.pro.R;

public class ReadListAdapter extends ArrayAdapter<Object>          //old o
  implements Filterable
{
  //private static Context localContext1;
  protected final LayoutInflater a;
  protected final Object b;
  protected n c;
  protected final Object d;
  protected final af e;
  protected boolean f;
  private final ae g;
  private final boolean h;
  private final int i;
  private final Drawable ic_mark;
  private final Drawable ic_marked;
  private final Drawable ic_dark;
  private final Drawable ic_darked;
  private final Drawable ic_add;
  private final Drawable ic_added;
  private Map<Object, Object> p;
  private boolean q;
  private HashMap<Integer, Boolean> r;

  public ReadListAdapter(af af1, boolean paramBoolean, int paramInt)
  {
    super((Context)af1, R.layout.row,  new ArrayList<Object>());
    this.p = new HashMap<Object, Object>();
    this.q = false;
    this.b = new Object();
    this.d = new Object();
    this.f = true;
    this.h = paramBoolean;
    this.i = paramInt;
    Context context = (Context)af1;
    LayoutInflater localLayoutInflater = (LayoutInflater)context.getSystemService("layout_inflater");
    this.a = localLayoutInflater;
    this.ic_mark = context.getResources().getDrawable(R.drawable.ic_row_mark);
    this.ic_marked = context.getResources().getDrawable(R.drawable.ic_row_marked);
    this.ic_dark = context.getResources().getDrawable(R.drawable.ic_row_dark_mark);
    this.ic_darked = context.getResources().getDrawable(R.drawable.ic_row_dark_marked);
    this.ic_add = context.getResources().getDrawable(R.drawable.ic_row_add);
    this.ic_added = context.getResources().getDrawable(R.drawable.ic_row_added);
    this.e = af1;
    this.g = new ae(this);
  }
  
  static Map<Object, Object> a(ReadListAdapter o1)
  {
      return o1.p;
  }

  static Map<Integer, Boolean> b(ReadListAdapter o1)
  {
      return o1.r;
  }

  static Drawable getICMarked(ReadListAdapter o1)
  {
      return o1.ic_marked;
  }

  static Drawable getICMark(ReadListAdapter o1)
  {
      return o1.ic_mark;
  }

  static int e(ReadListAdapter o1)
  {
      return o1.i;
  }

  static Drawable getAdded(ReadListAdapter o1)
  {
      return o1.ic_added;
  }

  static Drawable getICDarked(ReadListAdapter o1)
  {
      return o1.ic_darked;
  }

  static Drawable getICAdd(ReadListAdapter o1)
  {
      return o1.ic_add;
  }

  static Drawable getICDark(ReadListAdapter o1)
  {
      return o1.ic_dark;
  }


  public int a()
  {
    synchronized (this.b)
    {
    	int i1;
    	if(c == null)
        {
            i1 = 0;
        } else
        {
            int j1 = c.b();
            i1 = j1;
        }
        return i1;
    }
  }

  public final void a(int paramInt)
  {
	  ac ac1 = b();
      if(ac1 != null)
          ac1.a(paramInt);
      a(true, false);
  }

  public final void a(l paraml)
  {
    synchronized (this.b)
    {
    	try
    	{
      if ((this.c == null) || (paraml == null))
        return;
    	}
    	catch(Exception e)
    	{
      App.handlerPost(new t(this, paraml));
    	}
    }
  }

  public final void a(l paraml, View paramView)
  {
    if (this.r.remove(paraml.a()) == null)
    {
      this.r.put(paraml.a(), true);
    }
    aq.a((aq)paramView.getTag());
  }

  public final void a(n paramn, boolean paramBoolean)
  {
      synchronized (this.b)
      {
    	  try
    	  {
        if (this.c != null)
        this.c.l();
        this.c = paramn;
        if (paramn == null)
        {
        if (paramBoolean)
        {
        a(true, true);
        }
        else
        {
        	this.f=true;
            if (b() != null)
            {
              this.g.filter(b().b());
            }
        }
        notifyDataSetChanged();
        }
    	  }
    	  catch(Exception e)
    	  {
    		  this.g.filter("");
    	  }
      }
      
  }

  public final void a(CharSequence paramCharSequence)
  {
    this.g.filter(paramCharSequence);
  }

  public final void a(String s1)
  {
//	  Iterator iterator = p.entrySet().iterator();
//      do
//      {
//          do
//          {
//              if(!iterator.hasNext())
//                  return;
//              iterator.next();
//          } //while(!((String)iterator.getValue()).equals(s1));
//          aq aq1 = (aq)((View)getKey()).getTag();
//          android.graphics.Bitmap bitmap = af.q().i().a(s1);
//          aq1.a.setImageBitmap(bitmap);
//      } while(true);
////    Iterator localIterator = this.p.entrySet().iterator();
//    while (true)
//    {
//      if (!localIterator.hasNext())
//        return;
//      this = (Map.Entry)localIterator.next();
//      if (!((String)getValue()).equals(paramString))
//        continue;
//      aq localaq = (aq)((View)getKey()).getTag();
//      Bitmap localBitmap = com.kksoft.readcm.a.Appconfig.q().i().a(paramString);
//      localaq.a.setImageBitmap(localBitmap);
//    }
  }

  public final void a(boolean flag)
  {
	  if(flag)
      {
          r = new HashMap<Integer, Boolean>();;
      } else
      {
          r = null;
      }
      q = flag;
      notifyDataSetChanged();
  }

  protected void a(boolean paramBoolean1, boolean paramBoolean2)
  {
    synchronized (this.b)
    {
      if (this.c == null)
        return;
      n localn = this.c;
      ac localac = b();
      s locals = new s(this);
      localn.a(localac, paramBoolean1, paramBoolean2, locals);
    }
  }

  protected final ac b()
  {
	  synchronized(d)
      {
		  ac ac1;
          if(e == null)
          {
        	  ac1 = null;
          } else
          {
              ac1 = e.J();
          }
          return ac1;
      }
  }

  public final boolean b(int i1)
  {
	  boolean flag;
      if(i1 == 0)
      {
          flag = false;
      } else
      {
          this.r.put(i1, true);
          flag = true;
      }
      return flag;
  }

  public boolean c()
  {
	  synchronized(b)
      {   boolean flag;
          if(c == null)
          {
              flag = false;
          } else
          {
              flag = c.h();
          }
          return flag;
      }
  }

  public final HashMap<Integer, Boolean> d()
  {
	  return this.r;
  }

  public final int e()
  {
	  int i1;
      if(r != null)
          i1 = r.size();
      else
          i1 = 0;
      return i1;
  }

  public final boolean f()
  {
    return this.q;
  }

  public final void g()
  {
	  a(((n) (null)), true);
      p.clear();
  }

  public int getCount()
  {
	  synchronized(b)
      {int i1;
          if(c == null)
          {
              i1 = 0;
          } else
          {
              int j1 = c.g();
              i1 = j1;
          }
          return i1;
      }
  }

  public Filter getFilter()
  {
    return this.g;
  }

  public Object getItem(int i1)
  {
	  synchronized(b)
      {
		  Object obj;
          if(c == null)
          {
              obj = null;
          } else
          {
              l l1 = c.b(i1);
              obj = l1;
          }
          return obj;
      }
  }

  public long getItemId(int paramInt)
  {
    return paramInt;
  }

  public int getItemViewType(int paramInt)
  {
	  byte byte0;
      if(q)
      {
          if(i == 2)
              byte0 = 2;
          else
              byte0 = 3;
      } else
      if(h)
          byte0 = 1;
      else
          byte0 = 0;
      return byte0;
  }

  public int getPosition(Object obj)
  {
	  synchronized(b)
      {
		  int i1;
          if(c == null)
          {
              i1 = -1;
          } else
          {
              n n1 = c;
              l l1 = (l)obj;
              int j1 = n1.d(l1);
              i1 = j1;
          }
          return i1;
      }
  }

  public View getView(int i1, View view, ViewGroup viewgroup)
  {
	  int k1;
      if(getCount() - 1 == i1)
          synchronized(d)
          {
              if(e != null)
                  e.G();
          }
      k1 = getItemViewType(i1);
      
      switch(k1)
      {
      	default:
            return null;
      		//break;
      	case 0:
      		//a.inflate(R.layout.view_list_row, viewgroup, false).setTag(new aq(this, view, k1));
      		View localView1 = this.a.inflate(R.layout.view_list_row, viewgroup, false);
        aq localaq = new aq(this, localView1, k1);
        localView1.setTag(localaq);
        localaq.a((l)getItem(i1), k1);
        return localView1;
   
      	case 1:
      		//a.inflate(R.layout.view_list_row_currently_reading, viewgroup, false).setTag(new aq(this, view, k1));
      		View localView11 = this.a.inflate(R.layout.view_list_row_currently_reading, viewgroup, false);
            aq localaq1 = new aq(this, localView11, k1);
            localView11.setTag(localaq1);
            localaq1.a((l)getItem(i1), k1);
            return localView11;
      	case 2:
      		//a.inflate(R.layout.view_list_row_bulk_mark, viewgroup, false).setTag(new aq(this, view, k1));
      		View localView12 = this.a.inflate(R.layout.view_list_row_bulk_mark, viewgroup, false);
            aq localaq2 = new aq(this, localView12, k1);
            localView12.setTag(localaq2);
            localaq2.a((l)getItem(i1), k1);
            return localView12;
      	case 3:
      		//a.inflate(R.layout.view_list_row_bulk_edit, viewgroup, false).setTag(new aq(this, view, k1));
      		View localView13 = this.a.inflate(R.layout.view_list_row_bulk_edit, viewgroup, false);
            aq localaq3 = new aq(this, localView13, k1);
            localView13.setTag(localaq3);
            localaq3.a((l)getItem(i1), k1);
            return localView13;
      }
  }

  public int getViewTypeCount()
  {
    return 4;
  }

  public void notifyDataSetChanged()
  {
	  super.notifyDataSetChanged();
      synchronized(d)
      {
          if(e != null)
              e.I();
      }
  }
}